
using System;
using Gnome;
using Gdk;

namespace DiaCanvas
{
	public class Romboide:Figura
	{
		protected int _x;
		protected int _y;
		private int _height;
		private int _width;
		
		private Gnome.CanvasPolygon _fig;
		
		private bool _bDrag;
		
		private Gdk.Point _oldPoint;
		
		override protected Gnome.CanvasShape Shape { get { return this._fig; }}
		
		public Romboide(Gdk.Point p, int w, int h, Gnome.Canvas c):base(c)
		{
			this._point = p;
			
			this._height = h;
			this._width = w;
		
			CalculateControlPoints();
		
		}
		
		protected override void CalculateControlPoints()
		{
			int z = 10;
		
			this._points = new Gdk.Point[4];
			this._points.SetValue( new Point( this._point.X + this._width/2  , this._point.Y - z ),0);
			this._points.SetValue( new Point(this._point.X +this._width/2  -z ,this._point.Y-this._height/2  ),1);
			this._points.SetValue( new Point(this._point.X - this._width /2  ,this._point.Y -this._height +z ),2);
			this._points.SetValue( new Point(this._point.X - this._width /2  + z,this._point.Y - this._height/2 ),3);
		}
		
		override protected void Resize(Object obj, EventButton ev)
		{
			double dx = ev.X - this._oldPoint.X;
			double dy = ev.Y - this._oldPoint.Y;
			
					
		}
		
		override public string toString()
		{
			return "Este es un romboide";
		}
		

		
		public override FiguraType Type
		{
			get 
			{
				return FiguraType.Romboide;
			}
		}
		
		override public void draw()
		{
			Write("Dibujando el Romboide"); 
			
			this._fig = new Gnome.CanvasPolygon(this._canvas.Root());
			
	        this._fig.Points = new CanvasPoints (new double[]{
	        								this._x,this._y, 
	        								this._x+this._width,this._y, 
	        								this._x+this._width-this._height/2,this._y-this._height,
	        								this._x-this._height/2,this._y-this._height});
			
			Console.WriteLine(this._fig.Points.ToString());		
			this._fig.CanvasEvent += new Gnome.CanvasEventHandler(CanvasEvent);
						
			this._fig.OutlineColor = this._color.ForeGround;
			this._fig.FillColor = this._color.BackGround;
       		this._fig.WidthPixels = 1;
       		this._fig.Show();
			
			DrawControlPoints();
			
		}
		
		public void CanvasEvent(object obj, Gnome.CanvasEventArgs args)
		{

			EventButton ev = new EventButton (args.Event.Handle);
			switch (ev.Type) 
			{
				case EventType.MotionNotify:
					if ( this._bDrag )
					{
						Move(ev);
					}
					break;
					
				case EventType.EnterNotify:
					MouseEnter(obj,args);
					break;
	
					
				case EventType.LeaveNotify:
					MouseLeave(obj,args);
					break;
	
				case EventType.DragEnter:
					Write("Drag Enter");
					break;
					
				case EventType.ButtonPress:
					if ( this._bIn )
					{
						this._bDrag = true;
						this._oldPoint.X = (int)ev.X;
						this._oldPoint.Y = (int)ev.Y;
					}
					break;
					
				case EventType.ButtonRelease:
					if ( this._bDrag )
					{
						Move(ev);
					}
					this._bDrag = false;
					break;
			}

		}
		
		protected override void ChangeColor()
		{
			

		}
		
	}
}
